<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String basePath = "http://106.53.67.228/";
%>
<html>
<head>
    <title>Title</title>
    <script type="text/javascript" src="<c:url value="/static/js/jquery-3.4.1.min.js"/>"></script>
    <link rel="stylesheet" href="<c:url value="/pager/css/pages.css" />">
    <link rel="stylesheet" href="<c:url value="/static/css/read.css "/>">
    <link rel="stylesheet" href="<c:url value="/static/css/main.css "/>">
</head>
<body>
<div class="frame-header" style="background-color: #FCF8E3;">
    <div class="frame-header-content">
        <div class="logo"><a href="<c:url value="/index" /> " title="畅读小说网">畅读小说网</a></div>
        <div class="searchbox">
            <form action="<c:url value="/novel/findNovel" />" name="search-form" method="post">
                <input type="text"  class="text" style="height: 42px" name="novel.novelname" value="" onfocus="(function(o){if(o.value=='诛邪武神'){o.value='';o.className='focus'}})(this);" onblur="(function(o){if(o.value==''){o.value='诛邪武神';o.className='';}})(this)" autocomplete="off">
                <button type="submit" class="searchbtn">搜书</button>
            </form>
        </div>
        <div class="frame-operate">
            <div class="frame-btn">
                <c:if test="${!pageBean.info.isFirstPage}">
                    <a href="<c:url value="/novel/read/${sessionScope.novelid}" />?pc=1${pageBean.url}"class="btn btn-primary btn-sm"><i class="pticon pticon-chevron-left"></i>首章</a>
                    <a href="<c:url value="/novel/read/${sessionScope.novelid}" />?pc=${pageBean.info.prePage}${pageBean.url}" class="btn btn-primary btn-sm"><i class="pticon pticon-chevron-left"></i> 上一章</a>
                </c:if>
                <a href="<c:url value="/novel/novelSearch?id=${sessionScope.novelid}" />" class="btn btn-default" title=""><i class="pticon pticon-list"></i> 目录</a>
                <c:if test="${!pageBean.info.isLastPage}">
                    <a href="<c:url value="/novel/read/${sessionScope.novelid}" />?pc=${pageBean.info.nextPage}${pageBean.url}" class="btn btn-primary">下一章 <i class="pticon pticon-chevron-right"></i></a>
                    <a href="<c:url value="/novel/read/${sessionScope.novelid}" />?pc=${pageBean.info.total}${pageBean.url}"class="btn btn-primary">最后一章 <i class="pticon pticon-chevron-right"></i></a>
                </c:if>
            </div>
        </div>
    </div>
</div>>
    <div id="readdiv">
        <c:forEach items="${pageBean.beanList}" var="p">
            <input type="hidden" id="chapter" value="${p.chapterurl}"/>
        <header>
            ${p.chaptername}
        </header>
        <main>

        </main>
        </c:forEach>
        <div class="htmleaf-content" style="position: relative;padding:5px;">
            <ul class="manu" style="position:absolute;right:0px;top:0px;">
                <c:if test="${!pageBean.info.isFirstPage}">
                    <li><a href="<c:url value="/novel/read/${sessionScope.novelid}" />?pc=1${pageBean.url}">首章</a></li>
                    <li>
                        <a href="<c:url value="/novel/read/${sessionScope.novelid}" />?pc=${pageBean.info.prePage}${pageBean.url}">上一章</a>
                    </li>
                </c:if>

                <c:if test="${!pageBean.info.isLastPage}">
                    <c:choose>
                    <c:when test="${pageBean.info.pageNum==pageBean.info.lastPage-1}">
                        <li>
                            <a href="<c:url value="/novel/read/${sessionScope.novelid}" />?pc=${pageBean.info.nextPage}${pageBean.url}">下一章</a>
                        </li>
                        <li>
                            <a href="<c:url value="/novel/read/${sessionScope.novelid}" />?pc=${pageBean.info.total}${pageBean.url}">最后一章</a>
                        </li>
                    </c:when>
                    <c:otherwise>
                        <li>
                            <a href="<c:url value="/novel/read/${sessionScope.novelid}" />?pc=${pageBean.info.nextPage}${pageBean.url}">下一章</a>
                        </li>
                        <li>
                            <a href="<c:url value="/novel/read/${sessionScope.novelid}" />?pc=${pageBean.info.total}${pageBean.url}">最后一章</a>
                        </li>
                    </c:otherwise>
                    </c:choose>
                </c:if>
            </ul>
        </div>
    </div>
<script>
    if(top.location != this.location){
        top.location.replace('${pageContext.request.contextPath}/loginAndRegist.jsp');
    }
    var chapterurl=$("#chapter").val();
    $.ajax({
        url:"<%=basePath%>"+chapterurl,
        type:"get",
        datatype:"text",
        success:function (data) {
            data = data.replace(/(\r)*\n/g,"<br/>").replace(/\s/g,"&nbsp;").replace(/(<br\s?\/?>)+/gi, '<br>');
            $("main").html("&nbsp&nbsp&nbsp&nbsp"+data);
        },
        error:function (data) {
            alert("请求失败！！");
        }
    });
</script>
</html>
